<template>
  <el-card class="home-sales">
    <div class="header-wrap">
      <div class="line"></div>
      <div>
        <el-tabs class="demo-tabs">
          <el-tab-pane label="销售额"></el-tab-pane>
          <el-tab-pane label="访问量"></el-tab-pane>
        </el-tabs>
      </div>
      <div class="header-right">
        <el-radio-group style="margin-bottom: 30px" v-model="selectorDate">
          <el-radio-button label="day">今日</el-radio-button>
          <el-radio-button label="week">本周</el-radio-button>
          <el-radio-button label="mon">本月</el-radio-button>
          <el-radio-button label="year">今年</el-radio-button>
        </el-radio-group>
        <div class="block">
          <span class="demonstration"></span>
          <el-date-picker
            v-model="showDate"
            type="daterange"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="YYYY-MM-DD"
          />
        </div>
      </div>
    </div>
    <div class="sales-chart-rank">
      <SalesChart />
    </div>
  </el-card>
</template>

<script lang="ts">
export default {
  name: 'HomeSales',
}
</script>

<script lang="ts" setup>
import dayjs from 'dayjs'
import SalesChart from './SalesChart.vue'
import { ref, watch } from 'vue'

const showDate = ref<any>([''])
const selectorDate = ref('')

watch(selectorDate, (newVal) => {
  let start, end
  switch (newVal) {
    case 'day':
      start = dayjs().format('YYYY-MM-DD')
      showDate.value = [start, start]
      return
    case 'week':
      start = dayjs().startOf('week').add(1, 'day').format('YYYY-MM-DD')
      end = dayjs().endOf('week').add(1, 'day').format('YYYY-MM-DD')
      showDate.value = [start, end]
      return
    case 'mon':
      start = dayjs().startOf('month').format('YYYY-MM-DD')
      end = dayjs().endOf('month').format('YYYY-MM-DD')
      showDate.value = [start, end]
      return
    case 'year':
      start = dayjs().startOf('year').format('YYYY-MM-DD')
      end = dayjs().endOf('year').format('YYYY-MM-DD')
      showDate.value = [start, end]
      return
  }
})
</script>

<style scoped lang="scss">
.block {
  margin-left: 10px;
}
.home-sales {
  margin: 20px 0;
}
.header-wrap {
  display: flex;
  justify-content: space-between;
  position: relative;
}
.line {
  position: absolute;
  top: 50px;
  width: 100%;
  height: 1px;
  background-color: #ccc;
}
.header-right {
  display: flex;
  align-items: flex-start;
}
</style>

<style lang="scss">
.header-wrap {
  .el-tabs__nav-wrap::after {
    display: none;
  }
  .el-tabs__item {
    height: 50px;
    width: 80px;
    padding-right: 0;
    padding-left: 0;
    text-align: center;
  }
}
</style>
